package com.hntest.service.impl;

import com.hntest.dao.RealAuthDao;
import com.hntest.entity.Pager;
import com.hntest.entity.RealAuth;
import com.hntest.service.RealAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("RealAuthService")
public class RealAuthServiceImpl implements RealAuthService {
    @Autowired
    private RealAuthDao realAuthDao;
    public void setRealAuthDao(RealAuthDao realAuthDao) {
        this.realAuthDao = realAuthDao;
    }

    @Override
    public int getCounts(RealAuth realAuth) {
        return realAuthDao.getCounts(realAuth);
    }

    @Override
    public List<RealAuth> getListByPage(Pager pager, RealAuth realAuth,String time1,String time2) {

        Map<String,Object> map = new HashMap<String, Object>();
        map.put("RealAuth",realAuth);
        System.out.println("------------------->"+time1);
        System.out.println("------------------->"+time2);
        if(time1!=null&&time1.equals("")){
            time1=null;
        }
        if(time2!=null&&time2.equals("")){
            time2=null;
        }
        map.put("time1",time1);
        map.put("time2",time2);
        map.put("pageStart",1);
        map.put("pageEnd",10000);
        int n = realAuthDao.getListByPage(map).size();
        pager.setTotalCounts(n);
        System.out.println("____________________%%%%%%%%%"+n);
        map.put("pageStart",(pager.getCurrPage()-1)*pager.getPageSize()+1);
        map.put("pageEnd",pager.getCurrPage()*pager.getPageSize());
        System.out.println("------------------->"+(pager.getCurrPage()-1)*pager.getPageSize()+1);
        System.out.println("------------------->"+pager.getCurrPage()*pager.getPageSize());
        List<RealAuth> list= realAuthDao.getListByPage(map);
        return list;
    }

    @Override
    public int insert(RealAuth realAuth) {
        System.out.println("正在新增");
        return realAuthDao.insert(realAuth);
    }

    @Override
    public int update(RealAuth realAuth) {
        System.out.println("正在修改");
        return realAuthDao.update(realAuth);
    }

    @Override
    public int selectState(int applier_id)
    {
        return realAuthDao.selectState(applier_id);
    }

    @Override
    public RealAuth getRealAuthById(int realauthid) {
        return realAuthDao.getRealAuthById(realauthid);
    }
}
